/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package model;

import java.io.IOException;
import org.kxml2.io.KXmlParser;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

/**
 *
 * @author zimi
 */
public class Ingredient {

    /**
     * Kolejność na liście składników
     */
    private int order;

    /**
     * W języku naturalnym: 2 kilo marchewki
     */
    private String description;

    private Product product;

    private Measure measure;



    public Ingredient(Product product, Measure measure) {
        this.product = product;
        this.measure = measure;
    }

    public Ingredient() {
    }

    public Ingredient(KXmlParser parser) throws XmlPullParserException, IOException {
        while (parser.nextTag() != XmlPullParser.END_TAG) {
            parser.require(XmlPullParser.START_TAG, null, null);
            String tagName = parser.getName();
            if (tagName.equals("order")) {
                this.order = Integer.parseInt(parser.nextText());
            }
            if (tagName.equals("description")) {
                this.description = parser.nextText();
            }
            if (tagName.equals("product")) {
                this.product = new Product(parser);
            }
            if (tagName.equals("measure")) {
                this.measure = new Measure(parser);
            }
            parser.require(XmlPullParser.END_TAG, null, null);
        }
    }

    public Measure getMeasure() {
        return measure;
    }

    public void setMeasure(Measure measure) {
        this.measure = measure;
    }

    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    public double calculateCalories() {
        throw new RuntimeException("todo");
    }

    public int getOrder() {
        return order;
    }

    public void setOrder(int order) {
        this.order = order;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }
    
}
